import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import HomeView from '../views/HomeView.vue'
import StudentView from '../views/student/StudentList.vue'

import ExamLabelView from '../views/examlabel/ExamLabelList.vue'
//import ExamListView from '../views/examlist/ExamListList.vue'
import { getToken } from '@/utils/auth'
import { ElMessageBox } from 'element-plus'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: LoginView
    },
    {
      path: '/',
      name: 'home',
      component: HomeView,
      children:[
        {
          path:"student",
          component:StudentView
        },
       
        {
          path:"examlabel",
          component:ExamLabelView
        }
      ]
    }
  ]
})
router.beforeEach((to,from,next)=>{
  if(to.path == '/login'){
    next();
  }else{
    let token=getToken();
    if (!token) {
      ElMessageBox.alert('您还未登录,请先登录', '提示', {
        confirmButtonText: '确定'
      })
      next('/login');
    }else{
      next();
    }
  }
})
export default router
